package threadpool;

import com.sun.jmx.snmp.tasks.Task;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
    三种线程池的性能比较
 */
public class Demo01 {
    public static void main(String[] args) {
        ExecutorService executorService1 = Executors.newSingleThreadExecutor();
        ExecutorService executorService2 = Executors.newFixedThreadPool(10);
        ExecutorService executorService3 = Executors.newCachedThreadPool();
        for(int i=0;i<100;i++){
            int finalI = i;
            executorService3.execute(new Task() {
                @Override
                public void cancel() {

                }

                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                        System.out.println(finalI);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}
